{"cells": [{"cell_type": "markdown", "id": "63c4b10f", "metadata": {}, "source": ["# Inventory Organizational Content"]}, {"cell_type": "markdown", "id": "42a813b1", "metadata": {}, "source": ["Being able to retrieve, display, analyze, and export the content within an organization Portal are important tasks for any admin. Here we will leverage the [ContentManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#contentmanager) and [UserManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#usermanager) classes of the GIS module, as well as some functionality from the [Pandas](https://pandas.pydata.org/docs/index.html) library, to accomplish those tasks."]}, {"cell_type": "markdown", "metadata": {"toc": true}, "source": ["<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n", "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Inventory-Organizational-Content\" data-toc-modified-id=\"Inventory-Organizational-Content-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Inventory Organizational Content</a></span><ul class=\"toc-item\"><li><span><a href=\"#Import-Libraries\" data-toc-modified-id=\"Import-Libraries-1.1\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Import Libraries</a></span></li><li><span><a href=\"#Connect-to-ArcGIS-Online\" data-toc-modified-id=\"Connect-to-ArcGIS-Online-1.2\"><span class=\"toc-item-num\">1.2&nbsp;&nbsp;</span>Connect to ArcGIS Online</a></span></li><li><span><a href=\"#Querying-Content\" data-toc-modified-id=\"Querying-Content-1.3\"><span class=\"toc-item-num\">1.3&nbsp;&nbsp;</span>Querying Content</a></span><ul class=\"toc-item\"><li><span><a href=\"#Searching-for-Content\" data-toc-modified-id=\"Searching-for-Content-1.3.1\"><span class=\"toc-item-num\">1.3.1&nbsp;&nbsp;</span>Searching for Content</a></span></li><li><span><a href=\"#Displaying-Content\" data-toc-modified-id=\"Displaying-Content-1.3.2\"><span class=\"toc-item-num\">1.3.2&nbsp;&nbsp;</span>Displaying Content</a></span></li><li><span><a href=\"#Sorting-Content\" data-toc-modified-id=\"Sorting-Content-1.3.3\"><span class=\"toc-item-num\">1.3.3&nbsp;&nbsp;</span>Sorting Content</a></span></li></ul></li><li><span><a href=\"#Querying-Organization-Content\" data-toc-modified-id=\"Querying-Organization-Content-1.4\"><span class=\"toc-item-num\">1.4&nbsp;&nbsp;</span>Querying Organization Content</a></span><ul class=\"toc-item\"><li><span><a href=\"#Searching-for-Organization-Members\" data-toc-modified-id=\"Searching-for-Organization-Members-1.4.1\"><span class=\"toc-item-num\">1.4.1&nbsp;&nbsp;</span>Searching for Organization Members</a></span></li><li><span><a href=\"#Getting-Member-Content\" data-toc-modified-id=\"Getting-Member-Content-1.4.2\"><span class=\"toc-item-num\">1.4.2&nbsp;&nbsp;</span>Getting Member Content</a></span></li><li><span><a href=\"#Compiling-Organization-Content\" data-toc-modified-id=\"Compiling-Organization-Content-1.4.3\"><span class=\"toc-item-num\">1.4.3&nbsp;&nbsp;</span>Compiling Organization Content</a></span></li></ul></li><li><span><a href=\"#Analyzing-Organization-Content-with-Pandas\" data-toc-modified-id=\"Analyzing-Organization-Content-with-Pandas-1.5\"><span class=\"toc-item-num\">1.5&nbsp;&nbsp;</span>Analyzing Organization Content with Pandas</a></span><ul class=\"toc-item\"><li><span><a href=\"#Filtering-the-Dataset\" data-toc-modified-id=\"Filtering-the-Dataset-1.5.1\"><span class=\"toc-item-num\">1.5.1&nbsp;&nbsp;</span>Filtering the Dataset</a></span></li><li><span><a href=\"#Accessing-Content-by-ID\" data-toc-modified-id=\"Accessing-Content-by-ID-1.5.2\"><span class=\"toc-item-num\">1.5.2&nbsp;&nbsp;</span>Accessing Content by ID</a></span></li></ul></li><li><span><a href=\"#Exporting-Data\" data-toc-modified-id=\"Exporting-Data-1.6\"><span class=\"toc-item-num\">1.6&nbsp;&nbsp;</span>Exporting Data</a></span></li></ul></li></ul></div>"]}, {"cell_type": "markdown", "id": "f40f8dc9", "metadata": {}, "source": ["## Import Libraries"]}, {"cell_type": "code", "execution_count": 1, "id": "744116bd", "metadata": {}, "outputs": [], "source": ["import pandas as pd\n", "from IPython.display import display\n", "\n", "import arcgis\n", "from arcgis.gis import GIS"]}, {"cell_type": "markdown", "id": "abca04ba", "metadata": {}, "source": ["## Connect to ArcGIS Online"]}, {"cell_type": "code", "execution_count": 3, "id": "381d4d51", "metadata": {}, "outputs": [{"data": {"text/html": ["<div class=\"9item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/user.html?user=api_data_owner' target='_blank'>\n", "                        <img src='https://geosaurus.maps.arcgis.com/home/js/arcgisonline/css/images/no-user-thumb.jpg' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\" style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/user.html?user=api_data_owner' target='_blank'><b>api_data owner</b>\n", "                        </a>\n", "                        <br/><br/><b>Bio</b>: None\n", "                        <br/><b>First Name</b>: api_data\n", "                        <br/><b>Last Name</b>: owner\n", "                        <br/><b>Username</b>: api_data_owner\n", "                        <br/><b>Joined</b>: April 10, 2019\n", "\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<User username:api_data_owner>"]}, "execution_count": 3, "metadata": {}, "output_type": "execute_result"}], "source": ["profile_name = \"my_dev_profile\"\n", "\n", "gis = GIS(profile=profile_name)\n", "gis.users.me"]}, {"cell_type": "markdown", "id": "c8806f8b", "metadata": {}, "source": ["## Querying Content"]}, {"cell_type": "markdown", "id": "4ae14d15", "metadata": {}, "source": ["To search for content within our organization, we can access the [ContentManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager) class via `gis.content()`. \n", "\n", "Using the [`advanced_search()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.advanced_search) method, we can query content belonging to a user by providing the string `\"owner: < username >\"`. By setting the `return_count` parameter of `advanced_search()` to `True`, we can simply return a single integer representing the number of items which that user owns.\n", "\n", "Let's return the number of items that belong to the user currently logged in:"]}, {"cell_type": "code", "execution_count": 4, "id": "79af1155", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["1240 items found for current user\n"]}], "source": ["qe = f\"owner: {gis.users.me.username}\"\n", "my_content_count = gis.content.advanced_search(query=qe,return_count=True)\n", "print(my_content_count, 'items found for current user')"]}, {"cell_type": "markdown", "id": "fef3d52e", "metadata": {}, "source": ["### Searching for Content"]}, {"cell_type": "markdown", "id": "55de05fb", "metadata": {}, "source": ["If we leave the `return_count` parameter as its default value `False`, then we will receive a response dictionary containing metadata about the query as well as a list of returned items in the `results` field.\n", "\n", "By setting the `max_items` parameter, we can limit the number of items that are returned in the `results` field."]}, {"cell_type": "code", "execution_count": 5, "id": "86ac5837", "metadata": {}, "outputs": [{"data": {"text/plain": ["{'query': 'owner: api_data_owner',\n", " 'total': 1240,\n", " 'start': 1,\n", " 'num': 3,\n", " 'nextStart': 4,\n", " 'results': [<Item title:\" Exposing patterns in land fires around the globe \" type:StoryMap owner:api_data_owner>,\n", "  <Item title:\" Exposing patterns in land fires around the globe \" type:StoryMap owner:api_data_owner>,\n", "  <Item title:\" Exposing patterns in land fires around the globe \" type:StoryMap owner:api_data_owner>]}"]}, "execution_count": 5, "metadata": {}, "output_type": "execute_result"}], "source": ["max_items = 3\n", "user_content = gis.content.advanced_search(query=qe, max_items=max_items)\n", "user_content"]}, {"cell_type": "markdown", "id": "152ff064", "metadata": {}, "source": ["### Displaying Content"]}, {"cell_type": "code", "execution_count": 6, "id": "8404b157", "metadata": {}, "outputs": [{"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=f1b6a842fbea45bca693c2fe6622bf70' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=f1b6a842fbea45bca693c2fe6622bf70' target='_blank'><b> Exposing patterns in land fires around the globe </b>\n", "                        </a>\n", "                        <br/>This story map analyzes global patterns in wildfires using spatial analysis tools in ArcGIS Pro with satellite thermal data. <img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">StoryMap by api_data_owner\n", "                        <br/>Last Modified: January 12, 2021\n", "                        <br/>0 comments, 1 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\" Exposing patterns in land fires around the globe \" type:StoryMap owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=fb2cdb23cece4c49a28e928d70511aa7' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=fb2cdb23cece4c49a28e928d70511aa7' target='_blank'><b> Exposing patterns in land fires around the globe </b>\n", "                        </a>\n", "                        <br/> This story map analyses global patterns in wildfires using spatial analysis tools in ArcGIS Pro with satellite thermal data . <img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">StoryMap by api_data_owner\n", "                        <br/>Last Modified: January 13, 2021\n", "                        <br/>0 comments, 1 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\" Exposing patterns in land fires around the globe \" type:StoryMap owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=7bfce9c3f0734d5896584b21d8fc2ba9' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=7bfce9c3f0734d5896584b21d8fc2ba9' target='_blank'><b> Exposing patterns in land fires around the globe </b>\n", "                        </a>\n", "                        <br/> This story map analyses global patterns in wildfires using spatial analysis tools in ArcGIS Pro with satellite thermal data . <img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">StoryMap by api_data_owner\n", "                        <br/>Last Modified: February 15, 2021\n", "                        <br/>0 comments, 0 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\" Exposing patterns in land fires around the globe \" type:StoryMap owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}], "source": ["# Displaying the result items through IPython.display.display()\n", "\n", "for item in user_content['results']:\n", "    display(item)"]}, {"cell_type": "markdown", "id": "d5435bc3", "metadata": {}, "source": ["It is also possible to have these items returned as dictionary objects by setting the `as_dict` parameter:"]}, {"cell_type": "code", "execution_count": 7, "id": "d6da0012", "metadata": {}, "outputs": [{"data": {"text/plain": ["[{'id': 'f1b6a842fbea45bca693c2fe6622bf70',\n", "  'owner': 'api_data_owner',\n", "  'created': 1610462632000,\n", "  'isOrgItem': True,\n", "  'modified': 1610462693000,\n", "  'guid': None,\n", "  'name': None,\n", "  'title': ' Exposing patterns in land fires around the globe ',\n", "  'type': 'StoryMap',\n", "  'typeKeywords': ['arcgis-storymaps',\n", "   'smdraftresourceid:draft_1599006014540.json',\n", "   'smpublisheddate:1599006014535',\n", "   'smstatuspublished',\n", "   'smversiondraft:20.35.0',\n", "   'smversionpublished:20.35.0',\n", "   'source-0f5ef7b723cd410f8e4e298d716bcd73',\n", "   'StoryMap',\n", "   'Web Application'],\n", "  'description': \"For decades, the NASA satellites Aqua and Terra have been monitoring potential wildfires with their MODIS sensors. In this StoryMap, I delve into the data archives to look at spatial and temporal patterns and trends.<div><br /></div><div>The\\xa0<a href='https://storymaps.arcgis.com/stories/5985c0af444c4fbbb53b92a1bf880503' rel='nofollow ugc' target='_blank'>original StoryMap</a>\\xa0has been translated into German, courtesy of\\xa0<a href='https://www.esri.de/de-de/home' rel='nofollow ugc' target='_blank'>Esri Deutschland</a>.\\xa0</div>\",\n", "  'tags': ['wildfire',\n", "   'fire',\n", "   'MODIS',\n", "   'satellite',\n", "   'ArcGIS Pro',\n", "   'spatial analysis'],\n", "  'snippet': 'This story map analyzes global patterns in wildfires using spatial analysis tools in ArcGIS Pro with satellite thermal data. ',\n", "  'thumbnail': 'thumbnail/ago_downloaded.jpg',\n", "  'documentation': None,\n", "  'extent': [],\n", "  'categories': [],\n", "  'spatialReference': None,\n", "  'accessInformation': 'Esri',\n", "  'licenseInfo': 'No restrictions on use or redistribution.\\xa0',\n", "  'culture': 'en-us',\n", "  'properties': None,\n", "  'advancedSettings': None,\n", "  'url': 'https://storymaps.arcgis.com/stories/f1b6a842fbea45bca693c2fe6622bf70',\n", "  'proxyFilter': None,\n", "  'access': 'private',\n", "  'size': -1,\n", "  'subInfo': 0,\n", "  'appCategories': [],\n", "  'industries': [],\n", "  'languages': [],\n", "  'largeThumbnail': None,\n", "  'banner': None,\n", "  'screenshots': [],\n", "  'listed': False,\n", "  'ownerFolder': None,\n", "  'protected': False,\n", "  'numComments': 0,\n", "  'numRatings': 0,\n", "  'avgRating': 0,\n", "  'numViews': 1,\n", "  'scoreCompleteness': 96,\n", "  'groupDesignations': None,\n", "  'contentOrigin': 'self'},\n", " {'id': 'fb2cdb23cece4c49a28e928d70511aa7',\n", "  'owner': 'api_data_owner',\n", "  'created': 1610515804000,\n", "  'isOrgItem': True,\n", "  'modified': 1610515854000,\n", "  'guid': None,\n", "  'name': None,\n", "  'title': ' Exposing patterns in land fires around the globe ',\n", "  'type': 'StoryMap',\n", "  'typeKeywords': ['arcgis-storymaps',\n", "   'smdraftresourceid:draft_1599006014540.json',\n", "   'smpublisheddate:1599006014535',\n", "   'smstatuspublished',\n", "   'smversiondraft:20.35.0',\n", "   'smversionpublished:20.35.0',\n", "   'source-0f5ef7b723cd410f8e4e298d716bcd73',\n", "   'StoryMap',\n", "   'Web Application'],\n", "  'description': \" For decades, the NASA satellites Aqua and Terra have been monitoring potential wildfires with their MODIS sensors .  In this StoryMap, I delve into the data archives to look at spatial and temporal patterns and trends. <div><br /></div><div> The <a href='https://storymaps.arcgis.com/stories/5985c0af444c4fbbb53b92a1bf880503' rel='nofollow ugc' target='_blank'> original StoryMap </a> has been translated into German, courtesy of <a href='https://www.esri.de/de-de/home' rel='nofollow ugc' target='_blank'> Esri Germany </a> . </div>\",\n", "  'tags': ['wildfire',\n", "   'fire',\n", "   'MODIS',\n", "   'satellite',\n", "   'ArcGIS Pro',\n", "   'spatial analysis'],\n", "  'snippet': ' This story map analyses global patterns in wildfires using spatial analysis tools in ArcGIS Pro with satellite thermal data . ',\n", "  'thumbnail': 'thumbnail/ago_downloaded.jpg',\n", "  'documentation': None,\n", "  'extent': [],\n", "  'categories': [],\n", "  'spatialReference': None,\n", "  'accessInformation': 'Esri',\n", "  'licenseInfo': 'No restrictions on use or redistribution.\\xa0',\n", "  'culture': 'en-us',\n", "  'properties': None,\n", "  'advancedSettings': None,\n", "  'url': 'https://storymaps.arcgis.com/stories/fb2cdb23cece4c49a28e928d70511aa7',\n", "  'proxyFilter': None,\n", "  'access': 'private',\n", "  'size': -1,\n", "  'subInfo': 0,\n", "  'appCategories': [],\n", "  'industries': [],\n", "  'languages': [],\n", "  'largeThumbnail': None,\n", "  'banner': None,\n", "  'screenshots': [],\n", "  'listed': False,\n", "  'ownerFolder': None,\n", "  'protected': False,\n", "  'numComments': 0,\n", "  'numRatings': 0,\n", "  'avgRating': 0,\n", "  'numViews': 1,\n", "  'scoreCompleteness': 98,\n", "  'groupDesignations': None,\n", "  'contentOrigin': 'self'},\n", " {'id': '7bfce9c3f0734d5896584b21d8fc2ba9',\n", "  'owner': 'api_data_owner',\n", "  'created': 1613391382000,\n", "  'isOrgItem': True,\n", "  'modified': 1613391500000,\n", "  'guid': None,\n", "  'name': None,\n", "  'title': ' Exposing patterns in land fires around the globe ',\n", "  'type': 'StoryMap',\n", "  'typeKeywords': ['arcgis-storymaps',\n", "   'smdraftresourceid:draft_1599006014540.json',\n", "   'smpublisheddate:1599006014535',\n", "   'smstatuspublished',\n", "   'smversiondraft:20.35.0',\n", "   'smversionpublished:20.35.0',\n", "   'source-0f5ef7b723cd410f8e4e298d716bcd73',\n", "   'StoryMap',\n", "   'Web Application'],\n", "  'description': \" For decades, the NASA satellites Aqua and Terra have been monitoring potential wildfires with their MODIS sensors .  In this StoryMap, I delve into the data archives to look at spatial and temporal patterns and trends. <div><br /></div><div> The <a href='https://storymaps.arcgis.com/stories/5985c0af444c4fbbb53b92a1bf880503' rel='nofollow ugc' target='_blank'> original StoryMap </a> has been translated into German, courtesy of <a href='https://www.esri.de/de-de/home' rel='nofollow ugc' target='_blank'> Esri Germany </a> . </div>\",\n", "  'tags': ['wildfire',\n", "   'fire',\n", "   'MODIS',\n", "   'satellite',\n", "   'ArcGIS Pro',\n", "   'spatial analysis'],\n", "  'snippet': ' This story map analyses global patterns in wildfires using spatial analysis tools in ArcGIS Pro with satellite thermal data . ',\n", "  'thumbnail': 'thumbnail/ago_downloaded.jpg',\n", "  'documentation': None,\n", "  'extent': [],\n", "  'categories': [],\n", "  'spatialReference': None,\n", "  'accessInformation': 'Esri',\n", "  'licenseInfo': 'No restrictions on use or redistribution.\\xa0',\n", "  'culture': 'en-us',\n", "  'properties': None,\n", "  'advancedSettings': None,\n", "  'url': 'https://storymaps.arcgis.com/stories/7bfce9c3f0734d5896584b21d8fc2ba9',\n", "  'proxyFilter': None,\n", "  'access': 'private',\n", "  'size': -1,\n", "  'subInfo': 0,\n", "  'appCategories': [],\n", "  'industries': [],\n", "  'languages': [],\n", "  'largeThumbnail': None,\n", "  'banner': None,\n", "  'screenshots': [],\n", "  'listed': False,\n", "  'ownerFolder': None,\n", "  'protected': False,\n", "  'numComments': 0,\n", "  'numRatings': 0,\n", "  'avgRating': 0,\n", "  'numViews': 0,\n", "  'scoreCompleteness': 98,\n", "  'groupDesignations': None,\n", "  'contentOrigin': 'self'}]"]}, "execution_count": 7, "metadata": {}, "output_type": "execute_result"}], "source": ["# return items as a dictionary with as_dict=True\n", "\n", "user_content_as_dict = gis.content.advanced_search(\n", "    query=qe, max_items=max_items,as_dict=True)\n", "user_content_as_dict['results']"]}, {"cell_type": "markdown", "id": "34d9e145", "metadata": {}, "source": ["### Sorting Content"]}, {"cell_type": "markdown", "id": "339448aa", "metadata": {}, "source": ["The `sort_field` and `sort_order` parameters of the [`advanced_search()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.advanced_search) method can be used to sort the returned content server side.\n", "\n", "Possible values for `sort_order` are `\"asc\"` for ascending or increasing order and `\"desc\"` for descending or decreasing order. Default values for the `sort_field` and `sort_order` parameters are `\"title\"` and `\"asc\"`, respectively.\n", "\n", "In this next example we'll search for the last 3 items that the current user modified by setting `sort_field=\"modified\"` and `sort_order=\"desc\"`:"]}, {"cell_type": "code", "execution_count": 8, "id": "645015ab", "metadata": {}, "outputs": [{"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=2647a386f5a04917b74cc4f40a48f57f' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=2647a386f5a04917b74cc4f40a48f57f' target='_blank'><b>Model Builder for Mussel Farm Detection</b>\n", "                        </a>\n", "                        <br/>Model Builder for Mussel Farm Detection<img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">Geoprocessing Sample by api_data_owner\n", "                        <br/>Last Modified: December 16, 2021\n", "                        <br/>0 comments, 0 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\"Model Builder for Mussel Farm Detection\" type:Geoprocessing Sample owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=ff6a48b3391c4a24b807af0eb08bb6c1' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=ff6a48b3391c4a24b807af0eb08bb6c1' target='_blank'><b>MusselFarms</b>\n", "                        </a>\n", "                        <br/>Feature layer with bounding boxes around mussel farms.<img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\">Feature Layer Collection by api_data_owner\n", "                        <br/>Last Modified: December 16, 2021\n", "                        <br/>0 comments, 2 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\"MusselFarms\" type:Feature Layer Collection owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=b46d3fe7378d4873b901ec035623089e' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=b46d3fe7378d4873b901ec035623089e' target='_blank'><b>MusselFarms</b>\n", "                        </a>\n", "                        <br/>Feature layer with bounding boxes around mussel farms.<img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">Service Definition by api_data_owner\n", "                        <br/>Last Modified: December 16, 2021\n", "                        <br/>0 comments, 1 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\"MusselFarms\" type:Service Definition owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}], "source": ["content_last_modified = gis.content.advanced_search(\n", "    query=qe, max_items=max_items, sort_field=\"modified\", sort_order=\"desc\")\n", "\n", "for item in content_last_modified['results']:\n", "    display(item)"]}, {"cell_type": "markdown", "id": "7ea4079f", "metadata": {}, "source": ["Here we return the first 3 items that the user created by setting `sort_field=\"created\"` and `sort_order=\"asc\"`:"]}, {"cell_type": "code", "execution_count": 9, "id": "112471bf", "metadata": {}, "outputs": [{"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=43ff80a8e6c64b0bb83231b32e562fca' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=43ff80a8e6c64b0bb83231b32e562fca' target='_blank'><b>Seattle Bike Routes</b>\n", "                        </a>\n", "                        <br/>Designate Bike Routes for Commuting Professionals<img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">Service Definition by api_data_owner\n", "                        <br/>Last Modified: April 23, 2019\n", "                        <br/>0 comments, 1 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\"Seattle Bike Routes\" type:Service Definition owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=718e55ece43846659f5e50969a4c67fd' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=718e55ece43846659f5e50969a4c67fd' target='_blank'><b>Seattle Bike Routes</b>\n", "                        </a>\n", "                        <br/>Designate Bike Routes for Commuting Professionals<img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\">Feature Layer Collection by api_data_owner\n", "                        <br/>Last Modified: April 23, 2019\n", "                        <br/>0 comments, 13 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\"Seattle Bike Routes\" type:Feature Layer Collection owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=74bc5c3e4ac7420db8448e00c4d3b48a' target='_blank'>\n", "                        <img src='http://static.arcgis.com/images/desktopapp.png' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=74bc5c3e4ac7420db8448e00c4d3b48a' target='_blank'><b>collisions</b>\n", "                        </a>\n", "                        <br/><img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/datafiles16.png' style=\"vertical-align:middle;\">Shapefile by api_data_owner\n", "                        <br/>Last Modified: April 26, 2019\n", "                        <br/>0 comments, 1 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\"collisions\" type:Shapefile owner:api_data_owner>"]}, "metadata": {}, "output_type": "display_data"}], "source": ["content_first_created = gis.content.advanced_search(query=qe, max_items=max_items, sort_field=\"created\", sort_order=\"asc\")\n", "\n", "for item in content_first_created['results']:\n", "    display(item)"]}, {"cell_type": "markdown", "id": "43b0a554", "metadata": {}, "source": ["## Querying Organization Content"]}, {"cell_type": "markdown", "id": "75cc805d", "metadata": {}, "source": ["### Searching for Organization Members"]}, {"cell_type": "markdown", "id": "0dd43cbc", "metadata": {}, "source": ["We can search for a list of the members within the organization by using the [UserManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#arcgis.gis.server.UserManager) class within the GIS module. Here we access the UserManager by calling `gis.users`, and use the [`search()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager.search) method to return a list of organization members. The `search()` method will return all users in the organization if no parameters are provided:"]}, {"cell_type": "code", "execution_count": 10, "id": "fe13e7c9", "metadata": {}, "outputs": [{"data": {"text/plain": ["<UserManager @ https://geosaurus.maps.arcgis.com>"]}, "execution_count": 10, "metadata": {}, "output_type": "execute_result"}], "source": ["# View UserManager object\n", "gis.users"]}, {"cell_type": "code", "execution_count": 11, "id": "d006c443", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["42 users found\n"]}, {"data": {"text/plain": ["[<User username:achapkowski_geosaurus>,\n", " <User username:amani_geosaurus>,\n", " <User username:andrew57>]"]}, "execution_count": 11, "metadata": {}, "output_type": "execute_result"}], "source": ["org_users = gis.users.search()\n", "print(f'{len(org_users)} users found')\n", "org_users[:3]"]}, {"cell_type": "code", "execution_count": 12, "id": "7773c879", "metadata": {}, "outputs": [{"data": {"text/html": ["<div class=\"9item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/user.html?user=amani_geosaurus' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\" style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/user.html?user=amani_geosaurus' target='_blank'><b>Atma Mani</b>\n", "                        </a>\n", "                        <br/><br/><b>Bio</b>: Product Engineering lead for the ArcGIS Python API development team\n", "                        <br/><b>First Name</b>: Atma\n", "                        <br/><b>Last Name</b>: Mani\n", "                        <br/><b>Username</b>: amani_geosaurus\n", "                        <br/><b>Joined</b>: December 21, 2016\n", "\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<User username:amani_geosaurus>"]}, "execution_count": 12, "metadata": {}, "output_type": "execute_result"}], "source": ["# Display a misc member\n", "org_member = org_users[1]\n", "org_member"]}, {"cell_type": "markdown", "id": "3d07ba3b", "metadata": {}, "source": ["### Getting Member Content"]}, {"cell_type": "markdown", "id": "ebb244c2", "metadata": {}, "source": ["Similarly to above, we can set `return_count=True` and see how many items this user has:"]}, {"cell_type": "code", "execution_count": 13, "id": "78af4b24", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Org member has 24 items\n"]}], "source": ["# See the number of member items\n", "qe = \"owner: \" + org_member.username\n", "member_content_count = gis.content.advanced_search(\n", "    query=qe, max_items=-1, return_count=True)\n", "print(f\"Org member has {member_content_count} items\")"]}, {"cell_type": "code", "execution_count": 14, "id": "44239cb7", "metadata": {}, "outputs": [{"data": {"text/plain": ["[<Item title:\"Demo Initiative1\" type:Hub Site Application owner:amani_geosaurus>,\n", " <Item title:\"Demo Initiative1\" type:Hub Initiative owner:amani_geosaurus>,\n", " <Item title:\"geotaggedphotos1\" type:Feature Layer Collection owner:amani_geosaurus>]"]}, "execution_count": 14, "metadata": {}, "output_type": "execute_result"}], "source": ["# Return <max_items> items from member\n", "max_items = 3\n", "\n", "member_content = gis.content.advanced_search(query=qe, max_items=max_items)\n", "member_content['results']"]}, {"cell_type": "markdown", "id": "60c942ef", "metadata": {}, "source": ["### Compiling Organization Content"]}, {"cell_type": "markdown", "id": "ed6595ea", "metadata": {}, "source": ["If we return all items for each user in the organization, we can compile those items into a single list representing all of the organizations content.\n", "\n", "We can remove the item limit for each query by setting `max_items=-1` in the `advanced_search()` function:"]}, {"cell_type": "code", "execution_count": 15, "id": "a7c8d14e", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["1848 items found in org\n"]}], "source": ["# return content for each user in org, compile into a single list\n", "\n", "org_content = []\n", "\n", "for user in org_users:\n", "    qe = f\"owner: {user.username}\"\n", "    user_content = gis.content.advanced_search(query=qe, max_items=-1)['results']\n", "    org_content += user_content\n", "    \n", "print(f\"{len(org_content)} items found in org\")"]}, {"cell_type": "markdown", "id": "850f4e7d", "metadata": {}, "source": ["## Analyzing Organization Content with Pandas"]}, {"cell_type": "markdown", "id": "965c56ae", "metadata": {}, "source": ["Let's put our compiled list into a pandas [DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) to easily view and filter our data"]}, {"cell_type": "code", "execution_count": 16, "id": "7fae7951", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", "    .dataframe tbody tr th:only-of-type {\n", "        vertical-align: middle;\n", "    }\n", "\n", "    .dataframe tbody tr th {\n", "        vertical-align: top;\n", "    }\n", "\n", "    .dataframe thead th {\n", "        text-align: right;\n", "    }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", "  <thead>\n", "    <tr style=\"text-align: right;\">\n", "      <th></th>\n", "      <th>id</th>\n", "      <th>owner</th>\n", "      <th>created</th>\n", "      <th>isOrgItem</th>\n", "      <th>modified</th>\n", "      <th>guid</th>\n", "      <th>name</th>\n", "      <th>title</th>\n", "      <th>type</th>\n", "      <th>typeKeywords</th>\n", "      <th>...</th>\n", "      <th>size</th>\n", "      <th>ownerFolder</th>\n", "      <th>commentsEnabled</th>\n", "      <th>itemControl</th>\n", "      <th>layers</th>\n", "      <th>tables</th>\n", "      <th>appProxies</th>\n", "      <th>protected</th>\n", "      <th>contentStatus</th>\n", "      <th>sourceUrl</th>\n", "    </tr>\n", "  </thead>\n", "  <tbody>\n", "    <tr>\n", "      <th>0</th>\n", "      <td>8ec563a6886f474c8d991e7748ab4c03</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1558567624000</td>\n", "      <td>True</td>\n", "      <td>1558567631000</td>\n", "      <td>None</td>\n", "      <td>None</td>\n", "      <td>Demo Initiative1</td>\n", "      <td>Hub Site Application</td>\n", "      <td>[Hub, hubSite, hubSolution, JavaScript, Map, M...</td>\n", "      <td>...</td>\n", "      <td>95654.0</td>\n", "      <td>None</td>\n", "      <td>True</td>\n", "      <td>update</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1</th>\n", "      <td>d1d2876870ab422488e425db4c400361</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1558567621000</td>\n", "      <td>True</td>\n", "      <td>1558567632000</td>\n", "      <td>None</td>\n", "      <td>None</td>\n", "      <td>Demo Initiative1</td>\n", "      <td>Hub Initiative</td>\n", "      <td>[Hub, hubInitiative, OpenData]</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>2</th>\n", "      <td>72567bd147fd478da9563bc56b434870</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1634162116000</td>\n", "      <td>True</td>\n", "      <td>1634162156000</td>\n", "      <td>None</td>\n", "      <td>geotaggedphotos1</td>\n", "      <td>geotaggedphotos1</td>\n", "      <td>Feature Service</td>\n", "      <td>[ArcGIS Server, Data, Feature Access, Feature ...</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>3</th>\n", "      <td>6fd3252f1ad044869dd4f949ea4b20cc</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1555049137000</td>\n", "      <td>True</td>\n", "      <td>1555049257000</td>\n", "      <td>None</td>\n", "      <td>None</td>\n", "      <td>hu_indy_18p</td>\n", "      <td>Feature Service</td>\n", "      <td>[ArcGIS Server, Data, Feature Access, Feature ...</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>4</th>\n", "      <td>1d3614ec5cc24382878533f8454c24a3</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1630112960000</td>\n", "      <td>True</td>\n", "      <td>1630112990000</td>\n", "      <td>None</td>\n", "      <td>1d3614ec5cc24382878533f8454c24a3.ipynb</td>\n", "      <td>intro to notebooks</td>\n", "      <td>Notebook</td>\n", "      <td>[Notebook, Python]</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "  </tbody>\n", "</table>\n", "<p>5 rows \u00d7 51 columns</p>\n", "</div>"], "text/plain": ["                                 id            owner        created  \\\n", "0  8ec563a6886f474c8d991e7748ab4c03  amani_geosaurus  1558567624000   \n", "1  d1d2876870ab422488e425db4c400361  amani_geosaurus  1558567621000   \n", "2  72567bd147fd478da9563bc56b434870  amani_geosaurus  1634162116000   \n", "3  6fd3252f1ad044869dd4f949ea4b20cc  amani_geosaurus  1555049137000   \n", "4  1d3614ec5cc24382878533f8454c24a3  amani_geosaurus  1630112960000   \n", "\n", "   isOrgItem       modified  guid                                    name  \\\n", "0       True  1558567631000  None                                    None   \n", "1       True  1558567632000  None                                    None   \n", "2       True  1634162156000  None                        geotaggedphotos1   \n", "3       True  1555049257000  None                                    None   \n", "4       True  1630112990000  None  1d3614ec5cc24382878533f8454c24a3.ipynb   \n", "\n", "                title                  type  \\\n", "0    Demo Initiative1  Hub Site Application   \n", "1    Demo Initiative1        Hub Initiative   \n", "2    geotaggedphotos1       Feature Service   \n", "3         hu_indy_18p       Feature Service   \n", "4  intro to notebooks              Notebook   \n", "\n", "                                        typeKeywords  ...     size  \\\n", "0  [Hub, hubSite, hubSolution, JavaScript, Map, M...  ...  95654.0   \n", "1                     [Hub, hubInitiative, OpenData]  ...      NaN   \n", "2  [ArcGIS Server, Data, Feature Access, Feature ...  ...      NaN   \n", "3  [ArcGIS Server, Data, Feature Access, Feature ...  ...      NaN   \n", "4                                 [Notebook, Python]  ...      NaN   \n", "\n", "  ownerFolder commentsEnabled itemControl layers tables appProxies protected  \\\n", "0        None            True      update    NaN    NaN        NaN       NaN   \n", "1         NaN             NaN         NaN    NaN    NaN        NaN       NaN   \n", "2         NaN             NaN         NaN    NaN    NaN        NaN       NaN   \n", "3         NaN             NaN         NaN    NaN    NaN        NaN       NaN   \n", "4         NaN             NaN         NaN    NaN    NaN        NaN       NaN   \n", "\n", "  contentStatus sourceUrl  \n", "0           NaN       NaN  \n", "1           NaN       NaN  \n", "2           NaN       NaN  \n", "3           NaN       NaN  \n", "4           NaN       NaN  \n", "\n", "[5 rows x 51 columns]"]}, "execution_count": 16, "metadata": {}, "output_type": "execute_result"}], "source": ["# Create DataFrame\n", "\n", "content_df = pd.DataFrame(org_content)\n", "content_df.head()"]}, {"cell_type": "markdown", "id": "3e3cb9ac", "metadata": {}, "source": ["We can use the pandas function [`value_counts()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) to see how many occurrences there are of each value for a particular column. Here we return the top 10 most frequently occurring item types and the number of instances they have:"]}, {"cell_type": "code", "execution_count": 17, "id": "07d8e877", "metadata": {}, "outputs": [{"data": {"text/plain": ["Feature Service          435\n", "Feature Collection       429\n", "Notebook                 342\n", "Shapefile                129\n", "StoryMap                  98\n", "Service Definition        76\n", "Image Collection          65\n", "File Geodatabase          43\n", "Deep Learning Package     43\n", "Web Map                   33\n", "Name: type, dtype: int64"]}, "execution_count": 17, "metadata": {}, "output_type": "execute_result"}], "source": ["# use value_counts() to see how many items you have with a particular key:value pair\n", "content_df.type.value_counts().head(10)"]}, {"cell_type": "markdown", "id": "25f3946f", "metadata": {}, "source": ["Another [`value_counts()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) example where we see the distribution of access levels for each of the items in the organization:"]}, {"cell_type": "code", "execution_count": 18, "id": "055ce1e0", "metadata": {}, "outputs": [{"data": {"text/plain": ["private    815\n", "org        518\n", "public     513\n", "shared       2\n", "Name: access, dtype: int64"]}, "execution_count": 18, "metadata": {}, "output_type": "execute_result"}], "source": ["content_df.access.value_counts()"]}, {"cell_type": "markdown", "id": "afb7847c", "metadata": {}, "source": ["Using the [`value_counts()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) function in conjunction with the [`groupby()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html) operation allows for an additional level of analysis. Here we see the breakdown of item types that each user has created:"]}, {"cell_type": "code", "execution_count": 19, "id": "55137546", "metadata": {}, "outputs": [{"data": {"text/plain": ["owner                type                \n", "ArcGISPyAPIBot       Notebook                31\n", "                     Feature Service          4\n", "                     CSV                      1\n", "                     StoryMap                 1\n", "                     Web Map                  1\n", "DavidJVitale         Feature Service          1\n", "                     Web Map                  1\n", "MMajumdar_geosaurus  Hub Site Application     1\n", "amani_geosaurus      Feature Service          6\n", "                     Notebook                 4\n", "Name: type, dtype: int64"]}, "execution_count": 19, "metadata": {}, "output_type": "execute_result"}], "source": ["content_df.groupby('owner').type.value_counts().head(10)"]}, {"cell_type": "code", "execution_count": 20, "id": "9555af52", "metadata": {}, "outputs": [{"data": {"text/plain": ["type             access \n", "API Key          private    1\n", "Application      public     1\n", "CSV              public     9\n", "                 private    8\n", "CSV Collection   private    2\n", "                 public     1\n", "Code Attachment  public     2\n", "Code Sample      public     6\n", "Dashboard        public     5\n", "                 org        2\n", "Name: access, dtype: int64"]}, "execution_count": 20, "metadata": {}, "output_type": "execute_result"}], "source": ["# Viewing the number item types per access level within the org\n", "content_df.groupby('type').access.value_counts().head(10)"]}, {"cell_type": "markdown", "id": "24bf807c", "metadata": {}, "source": ["### Filtering the Dataset"]}, {"cell_type": "markdown", "id": "c1427876", "metadata": {}, "source": ["We can choose which columns we'd like to view, and the order we'd like to view them in, by providing the DataFrame with a list of strings matching column names:"]}, {"cell_type": "code", "execution_count": 21, "id": "c4402555", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", "    .dataframe tbody tr th:only-of-type {\n", "        vertical-align: middle;\n", "    }\n", "\n", "    .dataframe tbody tr th {\n", "        vertical-align: top;\n", "    }\n", "\n", "    .dataframe thead th {\n", "        text-align: right;\n", "    }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", "  <thead>\n", "    <tr style=\"text-align: right;\">\n", "      <th></th>\n", "      <th>id</th>\n", "      <th>title</th>\n", "      <th>owner</th>\n", "      <th>type</th>\n", "      <th>access</th>\n", "    </tr>\n", "  </thead>\n", "  <tbody>\n", "    <tr>\n", "      <th>0</th>\n", "      <td>8ec563a6886f474c8d991e7748ab4c03</td>\n", "      <td>Demo Initiative1</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Hub Site Application</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1</th>\n", "      <td>d1d2876870ab422488e425db4c400361</td>\n", "      <td>Demo Initiative1</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Hub Initiative</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>2</th>\n", "      <td>72567bd147fd478da9563bc56b434870</td>\n", "      <td>geotaggedphotos1</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>3</th>\n", "      <td>6fd3252f1ad044869dd4f949ea4b20cc</td>\n", "      <td>hu_indy_18p</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>4</th>\n", "      <td>1d3614ec5cc24382878533f8454c24a3</td>\n", "      <td>intro to notebooks</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Notebook</td>\n", "      <td>public</td>\n", "    </tr>\n", "  </tbody>\n", "</table>\n", "</div>"], "text/plain": ["                                 id               title            owner  \\\n", "0  8ec563a6886f474c8d991e7748ab4c03    Demo Initiative1  amani_geosaurus   \n", "1  d1d2876870ab422488e425db4c400361    Demo Initiative1  amani_geosaurus   \n", "2  72567bd147fd478da9563bc56b434870    geotaggedphotos1  amani_geosaurus   \n", "3  6fd3252f1ad044869dd4f949ea4b20cc         hu_indy_18p  amani_geosaurus   \n", "4  1d3614ec5cc24382878533f8454c24a3  intro to notebooks  amani_geosaurus   \n", "\n", "                   type  access  \n", "0  Hub Site Application     org  \n", "1        Hub Initiative     org  \n", "2       Feature Service     org  \n", "3       Feature Service  public  \n", "4              Notebook  public  "]}, "execution_count": 21, "metadata": {}, "output_type": "execute_result"}], "source": ["view_columns = ['id','title','owner','type','access']\n", "content_df[view_columns].head()"]}, {"cell_type": "markdown", "id": "2d2c814c", "metadata": {}, "source": ["Creating and applying Boolean masks is a very efficient way to the filter the rows of a DataFrame. By using standard operators such as `<`, `>`, `==` and `!=` on pandas Series objects (e.g. the columns of our DataFrame), we can create a new Series of `True` and `False` values, called a mask. When this mask is applied to the original DataFrame, a new DataFrame will be returned with only the rows corresponding to where the mask had a `True` value.\n", "\n", "Let's create a mask to represent all items with public level access:"]}, {"cell_type": "code", "execution_count": 22, "id": "c2a4f290", "metadata": {}, "outputs": [{"data": {"text/plain": ["0    False\n", "1    False\n", "2    False\n", "3     True\n", "4     True\n", "Name: access, dtype: bool"]}, "execution_count": 22, "metadata": {}, "output_type": "execute_result"}], "source": ["filter_value = 'public'\n", "filter_column = 'access'\n", "row_filter = content_df[filter_column]==filter_value\n", "row_filter.head()"]}, {"cell_type": "markdown", "id": "2fb3bef4", "metadata": {}, "source": ["Applying this mask to our DataFrame, we return all fields for objects which have `access=='public'`:"]}, {"cell_type": "code", "execution_count": 23, "id": "54534e8e", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["513 objects in filtered DataFrame\n"]}, {"data": {"text/html": ["<div>\n", "<style scoped>\n", "    .dataframe tbody tr th:only-of-type {\n", "        vertical-align: middle;\n", "    }\n", "\n", "    .dataframe tbody tr th {\n", "        vertical-align: top;\n", "    }\n", "\n", "    .dataframe thead th {\n", "        text-align: right;\n", "    }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", "  <thead>\n", "    <tr style=\"text-align: right;\">\n", "      <th></th>\n", "      <th>id</th>\n", "      <th>owner</th>\n", "      <th>created</th>\n", "      <th>isOrgItem</th>\n", "      <th>modified</th>\n", "      <th>guid</th>\n", "      <th>name</th>\n", "      <th>title</th>\n", "      <th>type</th>\n", "      <th>typeKeywords</th>\n", "      <th>...</th>\n", "      <th>size</th>\n", "      <th>ownerFolder</th>\n", "      <th>commentsEnabled</th>\n", "      <th>itemControl</th>\n", "      <th>layers</th>\n", "      <th>tables</th>\n", "      <th>appProxies</th>\n", "      <th>protected</th>\n", "      <th>contentStatus</th>\n", "      <th>sourceUrl</th>\n", "    </tr>\n", "  </thead>\n", "  <tbody>\n", "    <tr>\n", "      <th>3</th>\n", "      <td>6fd3252f1ad044869dd4f949ea4b20cc</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1555049137000</td>\n", "      <td>True</td>\n", "      <td>1555049257000</td>\n", "      <td>None</td>\n", "      <td>None</td>\n", "      <td>hu_indy_18p</td>\n", "      <td>Feature Service</td>\n", "      <td>[ArcGIS Server, Data, Feature Access, Feature ...</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>4</th>\n", "      <td>1d3614ec5cc24382878533f8454c24a3</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1630112960000</td>\n", "      <td>True</td>\n", "      <td>1630112990000</td>\n", "      <td>None</td>\n", "      <td>1d3614ec5cc24382878533f8454c24a3.ipynb</td>\n", "      <td>intro to notebooks</td>\n", "      <td>Notebook</td>\n", "      <td>[Notebook, Python]</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>5</th>\n", "      <td>67ec03dba0d44bb1924cd8b3aebf2db4</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1613548980000</td>\n", "      <td>True</td>\n", "      <td>1613548981000</td>\n", "      <td>None</td>\n", "      <td>KMZ_ContentType_Region_UnitedNations-3.zip</td>\n", "      <td>KMZ_ContentType_Region_UnitedNations-3</td>\n", "      <td>KML Collection</td>\n", "      <td>[KML Collection]</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>6</th>\n", "      <td>8df836df4d544067b715c296608beea4</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1591834702000</td>\n", "      <td>True</td>\n", "      <td>1591860089000</td>\n", "      <td>None</td>\n", "      <td>None</td>\n", "      <td>Lambda requests on a map</td>\n", "      <td>Web Map</td>\n", "      <td>[ArcGIS Online, Explorer Web Map, Map, Online ...</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "    <tr>\n", "      <th>7</th>\n", "      <td>8443e3c2473549f0b464a6a3f295acf9</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>1591655624000</td>\n", "      <td>True</td>\n", "      <td>1591655626000</td>\n", "      <td>None</td>\n", "      <td>None</td>\n", "      <td>lambda-credit-counter</td>\n", "      <td>Application</td>\n", "      <td>[Application, Registered App]</td>\n", "      <td>...</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "      <td>NaN</td>\n", "    </tr>\n", "  </tbody>\n", "</table>\n", "<p>5 rows \u00d7 51 columns</p>\n", "</div>"], "text/plain": ["                                 id            owner        created  \\\n", "3  6fd3252f1ad044869dd4f949ea4b20cc  amani_geosaurus  1555049137000   \n", "4  1d3614ec5cc24382878533f8454c24a3  amani_geosaurus  1630112960000   \n", "5  67ec03dba0d44bb1924cd8b3aebf2db4  amani_geosaurus  1613548980000   \n", "6  8df836df4d544067b715c296608beea4  amani_geosaurus  1591834702000   \n", "7  8443e3c2473549f0b464a6a3f295acf9  amani_geosaurus  1591655624000   \n", "\n", "   isOrgItem       modified  guid                                        name  \\\n", "3       True  1555049257000  None                                        None   \n", "4       True  1630112990000  None      1d3614ec5cc24382878533f8454c24a3.ipynb   \n", "5       True  1613548981000  None  KMZ_ContentType_Region_UnitedNations-3.zip   \n", "6       True  1591860089000  None                                        None   \n", "7       True  1591655626000  None                                        None   \n", "\n", "                                    title             type  \\\n", "3                             hu_indy_18p  Feature Service   \n", "4                      intro to notebooks         Notebook   \n", "5  KMZ_ContentType_Region_UnitedNations-3   KML Collection   \n", "6                Lambda requests on a map          Web Map   \n", "7                   lambda-credit-counter      Application   \n", "\n", "                                        typeKeywords  ... size ownerFolder  \\\n", "3  [ArcGIS Server, Data, Feature Access, Feature ...  ...  NaN         NaN   \n", "4                                 [Notebook, Python]  ...  NaN         NaN   \n", "5                                   [KML Collection]  ...  NaN         NaN   \n", "6  [ArcGIS Online, Explorer Web Map, Map, Online ...  ...  NaN         NaN   \n", "7                      [Application, Registered App]  ...  NaN         NaN   \n", "\n", "  commentsEnabled itemControl layers tables appProxies protected  \\\n", "3             NaN         NaN    NaN    NaN        NaN       NaN   \n", "4             NaN         NaN    NaN    NaN        NaN       NaN   \n", "5             NaN         NaN    NaN    NaN        NaN       NaN   \n", "6             NaN         NaN    NaN    NaN        NaN       NaN   \n", "7             NaN         NaN    NaN    NaN        NaN       NaN   \n", "\n", "  contentStatus sourceUrl  \n", "3           NaN       NaN  \n", "4           NaN       NaN  \n", "5           NaN       NaN  \n", "6           NaN       NaN  \n", "7           NaN       NaN  \n", "\n", "[5 rows x 51 columns]"]}, "execution_count": 23, "metadata": {}, "output_type": "execute_result"}], "source": ["print(len(content_df[row_filter]), 'objects in filtered DataFrame')\n", "content_df[row_filter].head()"]}, {"cell_type": "markdown", "id": "9faa69eb", "metadata": {}, "source": ["We can apply both the column filter and Boolean mask at the same time to reduce the amount of information displayed:"]}, {"cell_type": "code", "execution_count": 24, "id": "ae8d1fa4", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", "    .dataframe tbody tr th:only-of-type {\n", "        vertical-align: middle;\n", "    }\n", "\n", "    .dataframe tbody tr th {\n", "        vertical-align: top;\n", "    }\n", "\n", "    .dataframe thead th {\n", "        text-align: right;\n", "    }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", "  <thead>\n", "    <tr style=\"text-align: right;\">\n", "      <th></th>\n", "      <th>id</th>\n", "      <th>title</th>\n", "      <th>owner</th>\n", "      <th>type</th>\n", "      <th>access</th>\n", "    </tr>\n", "  </thead>\n", "  <tbody>\n", "    <tr>\n", "      <th>3</th>\n", "      <td>6fd3252f1ad044869dd4f949ea4b20cc</td>\n", "      <td>hu_indy_18p</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>4</th>\n", "      <td>1d3614ec5cc24382878533f8454c24a3</td>\n", "      <td>intro to notebooks</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Notebook</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>5</th>\n", "      <td>67ec03dba0d44bb1924cd8b3aebf2db4</td>\n", "      <td>KMZ_ContentType_Region_UnitedNations-3</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>KML Collection</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>6</th>\n", "      <td>8df836df4d544067b715c296608beea4</td>\n", "      <td>Lambda requests on a map</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>7</th>\n", "      <td>8443e3c2473549f0b464a6a3f295acf9</td>\n", "      <td>lambda-credit-counter</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Application</td>\n", "      <td>public</td>\n", "    </tr>\n", "  </tbody>\n", "</table>\n", "</div>"], "text/plain": ["                                 id                                   title  \\\n", "3  6fd3252f1ad044869dd4f949ea4b20cc                             hu_indy_18p   \n", "4  1d3614ec5cc24382878533f8454c24a3                      intro to notebooks   \n", "5  67ec03dba0d44bb1924cd8b3aebf2db4  KMZ_ContentType_Region_UnitedNations-3   \n", "6  8df836df4d544067b715c296608beea4                Lambda requests on a map   \n", "7  8443e3c2473549f0b464a6a3f295acf9                   lambda-credit-counter   \n", "\n", "             owner             type  access  \n", "3  amani_geosaurus  Feature Service  public  \n", "4  amani_geosaurus         Notebook  public  \n", "5  amani_geosaurus   KML Collection  public  \n", "6  amani_geosaurus          Web Map  public  \n", "7  amani_geosaurus      Application  public  "]}, "execution_count": 24, "metadata": {}, "output_type": "execute_result"}], "source": ["content_df[row_filter][view_columns].head()"]}, {"cell_type": "markdown", "id": "5a0345c2", "metadata": {}, "source": ["Another example where we create a Boolean mask for all objects of type `\"Web Map\"`:"]}, {"cell_type": "code", "execution_count": 25, "id": "8edd82c6", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", "    .dataframe tbody tr th:only-of-type {\n", "        vertical-align: middle;\n", "    }\n", "\n", "    .dataframe tbody tr th {\n", "        vertical-align: top;\n", "    }\n", "\n", "    .dataframe thead th {\n", "        text-align: right;\n", "    }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", "  <thead>\n", "    <tr style=\"text-align: right;\">\n", "      <th></th>\n", "      <th>id</th>\n", "      <th>title</th>\n", "      <th>owner</th>\n", "      <th>type</th>\n", "      <th>access</th>\n", "    </tr>\n", "  </thead>\n", "  <tbody>\n", "    <tr>\n", "      <th>6</th>\n", "      <td>8df836df4d544067b715c296608beea4</td>\n", "      <td>Lambda requests on a map</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>23</th>\n", "      <td>5776d859b5a84b1b96d5c5bbfcc0d3d3</td>\n", "      <td>WebMap for Landfall Spotlight Article</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>36</th>\n", "      <td>81ef30218b3f41e89019160faa4de099</td>\n", "      <td>Headless WebMap about Parks</td>\n", "      <td>andrew57</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>38</th>\n", "      <td>54fd67f260fe413da84ed4f2d9e1dac2</td>\n", "      <td>National Levee Database Map</td>\n", "      <td>andrew57</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>44</th>\n", "      <td>a478d4172870462dae95d0b26561e3ac</td>\n", "      <td>SarahAWebMapSample</td>\n", "      <td>andrew57</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>46</th>\n", "      <td>ac02f94f0b8d42e59c74fdf9fb249a06</td>\n", "      <td>VectorTileFromOtherSiteLayerandBasemap</td>\n", "      <td>andrew57</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>96</th>\n", "      <td>127a87ebeede4e6c919d43b600763a3b</td>\n", "      <td>Addresses Geocoded</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>private</td>\n", "    </tr>\n", "    <tr>\n", "      <th>291</th>\n", "      <td>7d76c6397380497f9879df74f80f0214</td>\n", "      <td>Brick Kilns around Jaipur 2019</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>292</th>\n", "      <td>e91b9226ef224e7da4f32cb034c8b94d</td>\n", "      <td>Brick Klinks around Delhi 2014</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>293</th>\n", "      <td>711b1725f6334aeca2151734b37d3c50</td>\n", "      <td>Brick Klinks around Delhi 2019</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>406</th>\n", "      <td>6527ca7eea2a4cad826e11f298d09500</td>\n", "      <td>Coastline_India</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>407</th>\n", "      <td>a3e8eda445c34e95bdef7aa75bdd8a77</td>\n", "      <td>Coastline_India_l8</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>483</th>\n", "      <td>7d4f5249de15493a9916c03e509b831c</td>\n", "      <td>slums_2004</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>484</th>\n", "      <td>f3f7d8c728e74230baeed747a5322ba5</td>\n", "      <td>slums_2014</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>542</th>\n", "      <td>2fecd25df8624a41b15dfc97ed4c8f98</td>\n", "      <td>Superresolution Inferenced Map</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>557</th>\n", "      <td>2051a50d9370428297dc08a87db4a43f</td>\n", "      <td>oma-test-map</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>558</th>\n", "      <td>7cb38a3325564607a81c0da5733bfbfc</td>\n", "      <td>oma-test-map-updates</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>private</td>\n", "    </tr>\n", "    <tr>\n", "      <th>559</th>\n", "      <td>966cba4a3bfe487692b305d923fe2777</td>\n", "      <td>oma-test-map-updates-052220</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>private</td>\n", "    </tr>\n", "    <tr>\n", "      <th>573</th>\n", "      <td>6b43fb3f165245e3b72eba2ff2357d98</td>\n", "      <td>Parcel_extraction_results_e02</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>private</td>\n", "    </tr>\n", "    <tr>\n", "      <th>823</th>\n", "      <td>2303b34ac97b4689bd5ff851d5982a96</td>\n", "      <td>USA_coastline</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>870</th>\n", "      <td>66db719c5a7844a0b681876f7cd4c269</td>\n", "      <td>wm-test-n-layers</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>871</th>\n", "      <td>d0772d26a75141f9ac11998c16b06eed</td>\n", "      <td>wm-test-n-layers-dgray</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>923</th>\n", "      <td>7fe016b30663401baf415f4dd1078d36</td>\n", "      <td>Extracted land parcels</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1311</th>\n", "      <td>6d8e89f6fb0a4c8a8bb5e059846425d9</td>\n", "      <td>Giraffes</td>\n", "      <td>ArcGISPyAPIBot</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1338</th>\n", "      <td>b270d508a6354c6c84510e83f94ebf19</td>\n", "      <td>API_downloads_across_globe</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1376</th>\n", "      <td>ebc72a274dff4315b703e5de0a894831</td>\n", "      <td>Location Allocation example of Pizza Stores in...</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1378</th>\n", "      <td>27a956e9da094da98ebba3312a456078</td>\n", "      <td>Map_View_Google Drive Image</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1380</th>\n", "      <td>e66622a75ac14fffaf2e8223025479a0</td>\n", "      <td>Mobiliario Madrid</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1802</th>\n", "      <td>c0da3fa83cd34379b49c56a33247910b</td>\n", "      <td>wMap5_withCharts</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1803</th>\n", "      <td>393e05923b7c4d289d305273b30a1ea3</td>\n", "      <td>testing</td>\n", "      <td>DavidJVitale</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1808</th>\n", "      <td>3c9ab685601748b9b55f06c6a529d070</td>\n", "      <td>Chicago Libraries 2012</td>\n", "      <td>jyaist_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1811</th>\n", "      <td>4aeed784e57043e49895293e576f732a</td>\n", "      <td>Guinea Power Plants</td>\n", "      <td>jyaist_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>shared</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1835</th>\n", "      <td>0c4170b6934245269ffc3f41acbb4a87</td>\n", "      <td>LeafPickupMap</td>\n", "      <td>naubry_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>org</td>\n", "    </tr>\n", "  </tbody>\n", "</table>\n", "</div>"], "text/plain": ["                                    id  \\\n", "6     8df836df4d544067b715c296608beea4   \n", "23    5776d859b5a84b1b96d5c5bbfcc0d3d3   \n", "36    81ef30218b3f41e89019160faa4de099   \n", "38    54fd67f260fe413da84ed4f2d9e1dac2   \n", "44    a478d4172870462dae95d0b26561e3ac   \n", "46    ac02f94f0b8d42e59c74fdf9fb249a06   \n", "96    127a87ebeede4e6c919d43b600763a3b   \n", "291   7d76c6397380497f9879df74f80f0214   \n", "292   e91b9226ef224e7da4f32cb034c8b94d   \n", "293   711b1725f6334aeca2151734b37d3c50   \n", "406   6527ca7eea2a4cad826e11f298d09500   \n", "407   a3e8eda445c34e95bdef7aa75bdd8a77   \n", "483   7d4f5249de15493a9916c03e509b831c   \n", "484   f3f7d8c728e74230baeed747a5322ba5   \n", "542   2fecd25df8624a41b15dfc97ed4c8f98   \n", "557   2051a50d9370428297dc08a87db4a43f   \n", "558   7cb38a3325564607a81c0da5733bfbfc   \n", "559   966cba4a3bfe487692b305d923fe2777   \n", "573   6b43fb3f165245e3b72eba2ff2357d98   \n", "823   2303b34ac97b4689bd5ff851d5982a96   \n", "870   66db719c5a7844a0b681876f7cd4c269   \n", "871   d0772d26a75141f9ac11998c16b06eed   \n", "923   7fe016b30663401baf415f4dd1078d36   \n", "1311  6d8e89f6fb0a4c8a8bb5e059846425d9   \n", "1338  b270d508a6354c6c84510e83f94ebf19   \n", "1376  ebc72a274dff4315b703e5de0a894831   \n", "1378  27a956e9da094da98ebba3312a456078   \n", "1380  e66622a75ac14fffaf2e8223025479a0   \n", "1802  c0da3fa83cd34379b49c56a33247910b   \n", "1803  393e05923b7c4d289d305273b30a1ea3   \n", "1808  3c9ab685601748b9b55f06c6a529d070   \n", "1811  4aeed784e57043e49895293e576f732a   \n", "1835  0c4170b6934245269ffc3f41acbb4a87   \n", "\n", "                                                  title             owner  \\\n", "6                              Lambda requests on a map   amani_geosaurus   \n", "23                WebMap for Landfall Spotlight Article   amani_geosaurus   \n", "36                          Headless WebMap about Parks          andrew57   \n", "38                          National Levee Database Map          andrew57   \n", "44                                   SarahAWebMapSample          andrew57   \n", "46               VectorTileFromOtherSiteLayerandBasemap          andrew57   \n", "96                                   Addresses Geocoded    api_data_owner   \n", "291                      Brick Kilns around Jaipur 2019    api_data_owner   \n", "292                      Brick Klinks around Delhi 2014    api_data_owner   \n", "293                      Brick Klinks around Delhi 2019    api_data_owner   \n", "406                                     Coastline_India    api_data_owner   \n", "407                                  Coastline_India_l8    api_data_owner   \n", "483                                          slums_2004    api_data_owner   \n", "484                                          slums_2014    api_data_owner   \n", "542                      Superresolution Inferenced Map    api_data_owner   \n", "557                                        oma-test-map    api_data_owner   \n", "558                                oma-test-map-updates    api_data_owner   \n", "559                         oma-test-map-updates-052220    api_data_owner   \n", "573                       Parcel_extraction_results_e02    api_data_owner   \n", "823                                       USA_coastline    api_data_owner   \n", "870                                    wm-test-n-layers    api_data_owner   \n", "871                              wm-test-n-layers-dgray    api_data_owner   \n", "923                              Extracted land parcels    api_data_owner   \n", "1311                                           Giraffes    ArcGISPyAPIBot   \n", "1338                         API_downloads_across_globe     arcgis_python   \n", "1376  Location Allocation example of Pizza Stores in...     arcgis_python   \n", "1378                        Map_View_Google Drive Image     arcgis_python   \n", "1380                                  Mobiliario Madrid     arcgis_python   \n", "1802                                   wMap5_withCharts     arcgis_python   \n", "1803                                            testing      DavidJVitale   \n", "1808                             Chicago Libraries 2012  jyaist_geosaurus   \n", "1811                                Guinea Power Plants  jyaist_geosaurus   \n", "1835                                      LeafPickupMap  naubry_geosaurus   \n", "\n", "         type   access  \n", "6     Web Map   public  \n", "23    Web Map   public  \n", "36    Web Map   public  \n", "38    Web Map   public  \n", "44    Web Map      org  \n", "46    Web Map   public  \n", "96    Web Map  private  \n", "291   Web Map   public  \n", "292   Web Map   public  \n", "293   Web Map   public  \n", "406   Web Map   public  \n", "407   Web Map   public  \n", "483   Web Map   public  \n", "484   Web Map   public  \n", "542   Web Map   public  \n", "557   Web Map      org  \n", "558   Web Map  private  \n", "559   Web Map  private  \n", "573   Web Map  private  \n", "823   Web Map   public  \n", "870   Web Map      org  \n", "871   Web Map      org  \n", "923   Web Map   public  \n", "1311  Web Map      org  \n", "1338  Web Map      org  \n", "1376  Web Map   public  \n", "1378  Web Map   public  \n", "1380  Web Map   public  \n", "1802  Web Map   public  \n", "1803  Web Map   public  \n", "1808  Web Map      org  \n", "1811  Web Map   shared  \n", "1835  Web Map      org  "]}, "execution_count": 25, "metadata": {}, "output_type": "execute_result"}], "source": ["filter_value = 'Web Map'\n", "filter_column = 'type'\n", "row_filter = content_df[filter_column]==filter_value\n", "content_df[row_filter][view_columns]"]}, {"cell_type": "markdown", "id": "9c85e358", "metadata": {}, "source": ["Boolean masks can also be combined to represent multiple filters. Here we combine the Web Map and Public masks to return all items in our organization which are public web maps:"]}, {"cell_type": "code", "execution_count": 26, "id": "299024e6", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", "    .dataframe tbody tr th:only-of-type {\n", "        vertical-align: middle;\n", "    }\n", "\n", "    .dataframe tbody tr th {\n", "        vertical-align: top;\n", "    }\n", "\n", "    .dataframe thead th {\n", "        text-align: right;\n", "    }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", "  <thead>\n", "    <tr style=\"text-align: right;\">\n", "      <th></th>\n", "      <th>id</th>\n", "      <th>title</th>\n", "      <th>owner</th>\n", "      <th>type</th>\n", "      <th>access</th>\n", "    </tr>\n", "  </thead>\n", "  <tbody>\n", "    <tr>\n", "      <th>6</th>\n", "      <td>8df836df4d544067b715c296608beea4</td>\n", "      <td>Lambda requests on a map</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>23</th>\n", "      <td>5776d859b5a84b1b96d5c5bbfcc0d3d3</td>\n", "      <td>WebMap for Landfall Spotlight Article</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>36</th>\n", "      <td>81ef30218b3f41e89019160faa4de099</td>\n", "      <td>Headless WebMap about Parks</td>\n", "      <td>andrew57</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>38</th>\n", "      <td>54fd67f260fe413da84ed4f2d9e1dac2</td>\n", "      <td>National Levee Database Map</td>\n", "      <td>andrew57</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>46</th>\n", "      <td>ac02f94f0b8d42e59c74fdf9fb249a06</td>\n", "      <td>VectorTileFromOtherSiteLayerandBasemap</td>\n", "      <td>andrew57</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>291</th>\n", "      <td>7d76c6397380497f9879df74f80f0214</td>\n", "      <td>Brick Kilns around Jaipur 2019</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>292</th>\n", "      <td>e91b9226ef224e7da4f32cb034c8b94d</td>\n", "      <td>Brick Klinks around Delhi 2014</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>293</th>\n", "      <td>711b1725f6334aeca2151734b37d3c50</td>\n", "      <td>Brick Klinks around Delhi 2019</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>406</th>\n", "      <td>6527ca7eea2a4cad826e11f298d09500</td>\n", "      <td>Coastline_India</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>407</th>\n", "      <td>a3e8eda445c34e95bdef7aa75bdd8a77</td>\n", "      <td>Coastline_India_l8</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>483</th>\n", "      <td>7d4f5249de15493a9916c03e509b831c</td>\n", "      <td>slums_2004</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>484</th>\n", "      <td>f3f7d8c728e74230baeed747a5322ba5</td>\n", "      <td>slums_2014</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>542</th>\n", "      <td>2fecd25df8624a41b15dfc97ed4c8f98</td>\n", "      <td>Superresolution Inferenced Map</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>823</th>\n", "      <td>2303b34ac97b4689bd5ff851d5982a96</td>\n", "      <td>USA_coastline</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>923</th>\n", "      <td>7fe016b30663401baf415f4dd1078d36</td>\n", "      <td>Extracted land parcels</td>\n", "      <td>api_data_owner</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1376</th>\n", "      <td>ebc72a274dff4315b703e5de0a894831</td>\n", "      <td>Location Allocation example of Pizza Stores in...</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1378</th>\n", "      <td>27a956e9da094da98ebba3312a456078</td>\n", "      <td>Map_View_Google Drive Image</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1380</th>\n", "      <td>e66622a75ac14fffaf2e8223025479a0</td>\n", "      <td>Mobiliario Madrid</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1802</th>\n", "      <td>c0da3fa83cd34379b49c56a33247910b</td>\n", "      <td>wMap5_withCharts</td>\n", "      <td>arcgis_python</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1803</th>\n", "      <td>393e05923b7c4d289d305273b30a1ea3</td>\n", "      <td>testing</td>\n", "      <td>DavidJVitale</td>\n", "      <td>Web Map</td>\n", "      <td>public</td>\n", "    </tr>\n", "  </tbody>\n", "</table>\n", "</div>"], "text/plain": ["                                    id  \\\n", "6     8df836df4d544067b715c296608beea4   \n", "23    5776d859b5a84b1b96d5c5bbfcc0d3d3   \n", "36    81ef30218b3f41e89019160faa4de099   \n", "38    54fd67f260fe413da84ed4f2d9e1dac2   \n", "46    ac02f94f0b8d42e59c74fdf9fb249a06   \n", "291   7d76c6397380497f9879df74f80f0214   \n", "292   e91b9226ef224e7da4f32cb034c8b94d   \n", "293   711b1725f6334aeca2151734b37d3c50   \n", "406   6527ca7eea2a4cad826e11f298d09500   \n", "407   a3e8eda445c34e95bdef7aa75bdd8a77   \n", "483   7d4f5249de15493a9916c03e509b831c   \n", "484   f3f7d8c728e74230baeed747a5322ba5   \n", "542   2fecd25df8624a41b15dfc97ed4c8f98   \n", "823   2303b34ac97b4689bd5ff851d5982a96   \n", "923   7fe016b30663401baf415f4dd1078d36   \n", "1376  ebc72a274dff4315b703e5de0a894831   \n", "1378  27a956e9da094da98ebba3312a456078   \n", "1380  e66622a75ac14fffaf2e8223025479a0   \n", "1802  c0da3fa83cd34379b49c56a33247910b   \n", "1803  393e05923b7c4d289d305273b30a1ea3   \n", "\n", "                                                  title            owner  \\\n", "6                              Lambda requests on a map  amani_geosaurus   \n", "23                WebMap for Landfall Spotlight Article  amani_geosaurus   \n", "36                          Headless WebMap about Parks         andrew57   \n", "38                          National Levee Database Map         andrew57   \n", "46               VectorTileFromOtherSiteLayerandBasemap         andrew57   \n", "291                      Brick Kilns around Jaipur 2019   api_data_owner   \n", "292                      Brick Klinks around Delhi 2014   api_data_owner   \n", "293                      Brick Klinks around Delhi 2019   api_data_owner   \n", "406                                     Coastline_India   api_data_owner   \n", "407                                  Coastline_India_l8   api_data_owner   \n", "483                                          slums_2004   api_data_owner   \n", "484                                          slums_2014   api_data_owner   \n", "542                      Superresolution Inferenced Map   api_data_owner   \n", "823                                       USA_coastline   api_data_owner   \n", "923                              Extracted land parcels   api_data_owner   \n", "1376  Location Allocation example of Pizza Stores in...    arcgis_python   \n", "1378                        Map_View_Google Drive Image    arcgis_python   \n", "1380                                  Mobiliario Madrid    arcgis_python   \n", "1802                                   wMap5_withCharts    arcgis_python   \n", "1803                                            testing     DavidJVitale   \n", "\n", "         type  access  \n", "6     Web Map  public  \n", "23    Web Map  public  \n", "36    Web Map  public  \n", "38    Web Map  public  \n", "46    Web Map  public  \n", "291   Web Map  public  \n", "292   Web Map  public  \n", "293   Web Map  public  \n", "406   Web Map  public  \n", "407   Web Map  public  \n", "483   Web Map  public  \n", "484   Web Map  public  \n", "542   Web Map  public  \n", "823   Web Map  public  \n", "923   Web Map  public  \n", "1376  Web Map  public  \n", "1378  Web Map  public  \n", "1380  Web Map  public  \n", "1802  Web Map  public  \n", "1803  Web Map  public  "]}, "execution_count": 26, "metadata": {}, "output_type": "execute_result"}], "source": ["# Combining masks\n", "web_map_filter = content_df.type=='Web Map'\n", "public_filter = content_df.access=='public'\n", "combined_mask = web_map_filter & public_filter\n", "\n", "content_df[combined_mask][view_columns]"]}, {"cell_type": "markdown", "id": "a893b341", "metadata": {}, "source": ["The [`apply()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html) method can also be used to generate masks that can't be created using the standard comparison operators. As long as the function called within the apply method has a Boolean output, then the result can be used as a mask to filter rows. Here we use a [lambda](https://www.w3schools.com/python/python_lambda.asp) function to return all items which have a type that ends with the word \"Service\"."]}, {"cell_type": "code", "execution_count": 27, "id": "d4f4e4b2", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", "    .dataframe tbody tr th:only-of-type {\n", "        vertical-align: middle;\n", "    }\n", "\n", "    .dataframe tbody tr th {\n", "        vertical-align: top;\n", "    }\n", "\n", "    .dataframe thead th {\n", "        text-align: right;\n", "    }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", "  <thead>\n", "    <tr style=\"text-align: right;\">\n", "      <th></th>\n", "      <th>id</th>\n", "      <th>title</th>\n", "      <th>owner</th>\n", "      <th>type</th>\n", "      <th>access</th>\n", "    </tr>\n", "  </thead>\n", "  <tbody>\n", "    <tr>\n", "      <th>2</th>\n", "      <td>72567bd147fd478da9563bc56b434870</td>\n", "      <td>geotaggedphotos1</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>3</th>\n", "      <td>6fd3252f1ad044869dd4f949ea4b20cc</td>\n", "      <td>hu_indy_18p</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>9</th>\n", "      <td>d77abcdc3f04488f84ad22bc7afdfcad</td>\n", "      <td>Landfall density 2</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Map Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>11</th>\n", "      <td>ffef49c345154bc5b24c8e2e39587ec4</td>\n", "      <td>Landfall Spotlight Article_WFL1</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>19</th>\n", "      <td>e0959e7018914be0931a9f15efb56c94</td>\n", "      <td>request_locations</td>\n", "      <td>amani_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>...</th>\n", "      <td>...</td>\n", "      <td>...</td>\n", "      <td>...</td>\n", "      <td>...</td>\n", "      <td>...</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1830</th>\n", "      <td>f129290c5da14d7884b26951eddd6b29</td>\n", "      <td>KingCo_PropertyInfo</td>\n", "      <td>maggarwal_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1832</th>\n", "      <td>af59408fd19a4a1c99e14ff09967e394</td>\n", "      <td>Uganda_Boundary</td>\n", "      <td>maggarwal_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1834</th>\n", "      <td>42e944d92e1346f5a4229aa76841e5c2</td>\n", "      <td>Leaf_Pickup_Routes</td>\n", "      <td>naubry_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>org</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1837</th>\n", "      <td>1cc19cce694e4caf95ce4471befd55b7</td>\n", "      <td>Vexcel_Houston_Nadir</td>\n", "      <td>rohitgeo</td>\n", "      <td>Image Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "    <tr>\n", "      <th>1846</th>\n", "      <td>b120ffa7170f4be0b5aaad8a284c6be5</td>\n", "      <td>Trailheads</td>\n", "      <td>yjiang_geosaurus</td>\n", "      <td>Feature Service</td>\n", "      <td>public</td>\n", "    </tr>\n", "  </tbody>\n", "</table>\n", "<p>451 rows \u00d7 5 columns</p>\n", "</div>"], "text/plain": ["                                    id                            title  \\\n", "2     72567bd147fd478da9563bc56b434870                 geotaggedphotos1   \n", "3     6fd3252f1ad044869dd4f949ea4b20cc                      hu_indy_18p   \n", "9     d77abcdc3f04488f84ad22bc7afdfcad               Landfall density 2   \n", "11    ffef49c345154bc5b24c8e2e39587ec4  Landfall Spotlight Article_WFL1   \n", "19    e0959e7018914be0931a9f15efb56c94                request_locations   \n", "...                                ...                              ...   \n", "1830  f129290c5da14d7884b26951eddd6b29              KingCo_PropertyInfo   \n", "1832  af59408fd19a4a1c99e14ff09967e394                  Uganda_Boundary   \n", "1834  42e944d92e1346f5a4229aa76841e5c2               Leaf_Pickup_Routes   \n", "1837  1cc19cce694e4caf95ce4471befd55b7             Vexcel_Houston_Nadir   \n", "1846  b120ffa7170f4be0b5aaad8a284c6be5                       Trailheads   \n", "\n", "                    owner             type  access  \n", "2         amani_geosaurus  Feature Service     org  \n", "3         amani_geosaurus  Feature Service  public  \n", "9         amani_geosaurus      Map Service  public  \n", "11        amani_geosaurus  Feature Service  public  \n", "19        amani_geosaurus  Feature Service  public  \n", "...                   ...              ...     ...  \n", "1830  maggarwal_geosaurus  Feature Service  public  \n", "1832  maggarwal_geosaurus  Feature Service  public  \n", "1834     naubry_geosaurus  Feature Service     org  \n", "1837             rohitgeo    Image Service  public  \n", "1846     yjiang_geosaurus  Feature Service  public  \n", "\n", "[451 rows x 5 columns]"]}, "execution_count": 27, "metadata": {}, "output_type": "execute_result"}], "source": ["# Creating masks with .apply and lambda functions\n", "\n", "service_filter = content_df.type.apply(lambda x: x.endswith('Service'))\n", "content_df[service_filter][view_columns]"]}, {"cell_type": "markdown", "id": "0a409c06", "metadata": {}, "source": ["### Accessing Content by ID"]}, {"cell_type": "markdown", "id": "736fa4d4", "metadata": {}, "source": ["Once we've identified an item of interest in our DataFrame, we can return the content of that item by providing its ID to the [ContentManager](https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html) `get()` method. If we know the index of the object in the DataFrame (i.e. the leftmost value), then we can access that row's information using the `loc()` method. From there we can get the id of the item and provide it to the get method."]}, {"cell_type": "code", "execution_count": 28, "id": "4d42d933", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Target index: 1846\n"]}], "source": ["# Return the index of the last item in the previous output\n", "# In this example the index column is labelled 'name'\n", "\n", "target_index = content_df[service_filter].iloc[-1].name\n", "print(\"Target index:\", target_index)"]}, {"cell_type": "code", "execution_count": 29, "id": "8e7b6506", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["b120ffa7170f4be0b5aaad8a284c6be5\n"]}, {"data": {"text/html": ["<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n", "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n", "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=b120ffa7170f4be0b5aaad8a284c6be5' target='_blank'>\n", "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n", "                       </a>\n", "                    </div>\n", "\n", "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n", "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=b120ffa7170f4be0b5aaad8a284c6be5' target='_blank'><b>Trailheads</b>\n", "                        </a>\n", "                        <br/><img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\">Feature Layer Collection by yjiang_geosaurus\n", "                        <br/>Last Modified: July 28, 2020\n", "                        <br/>0 comments, 16 views\n", "                    </div>\n", "                </div>\n", "                "], "text/plain": ["<Item title:\"Trailheads\" type:Feature Layer Collection owner:yjiang_geosaurus>"]}, "execution_count": 29, "metadata": {}, "output_type": "execute_result"}], "source": ["# Accessing items with content.get()\n", "target_data = content_df.loc[target_index]\n", "print(target_data.id)\n", "target_content = gis.content.get(target_data.id)\n", "target_content"]}, {"cell_type": "markdown", "id": "7cef5753", "metadata": {}, "source": ["For more information on using item ids, see this [community post](https://community.esri.com/t5/arcgis-online-blog/where-can-i-find-the-item-id-for-an-arcgis-online/ba-p/890284)."]}, {"cell_type": "markdown", "id": "cf9decc1", "metadata": {}, "source": ["## Exporting Data"]}, {"cell_type": "markdown", "id": "548344fd", "metadata": {}, "source": ["Pandas provides a convenient [`to_csv()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html) method which can be used to generate zipped and unzipped csv outputs. Simply provide your target path with the appropriate file extension and call the method on the DataFrame object you would like to export."]}, {"cell_type": "code", "execution_count": 30, "id": "1bfcb80e", "metadata": {}, "outputs": [], "source": ["# Exporting data to a csv\n", "target_path = \"org_content.csv\"\n", "content_df.to_csv(target_path)"]}, {"cell_type": "code", "execution_count": 31, "id": "87557547", "metadata": {}, "outputs": [], "source": ["# Exporting data to gzipped csv file\n", "target_path_gzip = \"org_content.csv.gz\"\n", "content_df.to_csv(target_path_gzip)"]}, {"cell_type": "code", "execution_count": 32, "id": "fa20d094", "metadata": {}, "outputs": [], "source": ["# Exporting data to zipped csv file\n", "target_path_zip = \"org_content.csv.zip\"\n", "content_df.to_csv(target_path_zip)"]}, {"cell_type": "markdown", "id": "47157c31", "metadata": {}, "source": ["Pandas also provides additional methods for exporting the data as different file formats (e.g. [`to_json()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_json.html), [`to_pickle()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_pickle.html), [`to_excel()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html)) which behave similarly."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.2"}, "toc": {"base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": {}, "toc_section_display": true, "toc_window_display": true}}, "nbformat": 4, "nbformat_minor": 5}